package com.enfry.common.util.excel;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {

	public void test() throws Exception {
		String excelConfigFileName = "test.xml"; //excel的导入模板配置
		File tempExcelFile = new File("E:\\test1.xls");//导入的excel数据文件
		ExcelParser excelParser = null;
		if(tempExcelFile.getName().endsWith(".xls")){
			excelParser = new ExcelParser();
		}else{
			excelParser = new XssfExcelParser();
		}
		//读取Excel配置文件完整路径
		String path = this.getClass().getClassLoader().getResource(excelConfigFileName).toString();  
		path = path.substring(6,path.length());
		String sheetNameInExcelConfigFile = "USERINFO";
		SheetParser sheetParser = new SheetParser();
		sheetParser.setStruct(SheetStruct.load(path, sheetNameInExcelConfigFile));
		sheetParser.setSheetName("test");
		excelParser.addSheetParser(sheetParser);

		// 解析所有excel 文件内容
		Map context = new HashMap();
		List[] temp = new List[0];
		temp = excelParser.parseExcel(context, tempExcelFile.getAbsolutePath());
		for (List list : temp) {
			for (Object object : list) {
				Map<String, Object> item = (Map<String, Object>)object;
				System.out.println(item);
			}
		}
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		try {
			main.test();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
